package pers.vic.test.some.reflaction;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.math.BigDecimal;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jboss.netty.buffer.BigEndianHeapChannelBuffer;

import com.alibaba.dubbo.container.Main;
import com.alibaba.fastjson.annotation.JSONField;

import pers.vic.util.ReflectionUtils;

public class Son extends Facther{
	
	private int age;

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
	
	
	public static void main(String[] args) throws Exception {
		System.out.println(test());
		
		Son s = Son.build();
		System.out.println(s);
		PropertyDescriptor descriptor = new PropertyDescriptor("name", Son.class);
		
		Field f = ReflectionUtils.getAccessibleField(s, "name");
		System.out.println(f.getAnnotation(JSONField.class).name());
		Object name = descriptor.getReadMethod().invoke(s);
		PropertyDescriptor descriptor2 = new PropertyDescriptor("age", Son.class);
		Object age = descriptor2.getReadMethod().invoke(s);
		System.out.println(name +  "  "   +age);
		
		System.out.println("....................................");
		Double a = 1.5d;
		Double b = 1.6d;
		Double diff = 0.1d;
		BigDecimal x = new BigDecimal(String.valueOf(a));
		BigDecimal y = new BigDecimal(String.valueOf(b));
		System.out.println(b-a == 0.1d);
		Double c = b - a;
		System.out.println(c);
		System.out.println(c.equals(diff));
		System.out.println(Math.abs(c) <= diff);
		BigDecimal z = y.subtract(x);
		BigDecimal u = BigDecimal.valueOf(diff);
		System.out.println(u);
		System.out.println(z.equals(u));
	
	}
	
	
	public static int test() {
		try {
			System.out.println("-------------111111");
			return 1;
		}catch(Exception e) {
			System.out.println("-------------22222");
			return 2;
		}finally {
			System.out.println("-------------33333");
		}
	}

	@Override
	public String toString() {
		return "Son [age=" + age + ", getName()=" + getName() + "]";
	}

	public static Son build() {
		Son son = new Son();
		son.setName(RandomStringUtils.random(5,"abcdefghijklmnopqrst"));
		son.setAge(Integer.valueOf(RandomStringUtils.random(2,"1234567890")));
		return son;
	}

}
